package com.coolingme.calculatebracket;

import com.coolingme.calculatebracket.expression.TerminalInterpreter;
import com.coolingme.calculatebracket.expression.nonterminal.AddInterpreter;
import com.coolingme.calculatebracket.expression.nonterminal.DivInterpreter;
import com.coolingme.calculatebracket.expression.nonterminal.MultiInterpreter;
import com.coolingme.calculatebracket.expression.nonterminal.SubInterpreter;

/**
 * @author wangyue
 * @date 2022/12/25 16:34
 */
public class OperatorUtil {
    public static boolean isBracketOperator(String symbol) {
        return (symbol.equals("(") || symbol.equals(")"));
    }
    public static boolean isBracketLeftOperator(String symbol) {
        return symbol.equals("(") ;
    }
    public static boolean isBracketRightOperator(String symbol) {
        return symbol.equals(")");
    }
    public static boolean isOperator(String symbol) {
        return (symbol.equals("+") || symbol.equals("-") || symbol.equals("*") || symbol.equals("/"));
    }

    public static boolean isOperatorAS(String symbol) {
        return (symbol.equals("+") || symbol.equals("-"));
    }
    public static boolean isOperatorMN(String symbol) {
        return (symbol.equals("*") || symbol.equals("/"));
    }
    public static TerminalInterpreter getInterpreter(IArithmeticInterpreter left, IArithmeticInterpreter right, String symbol) {
        if (symbol.equals("+")) {
            return new AddInterpreter(left, right);
        } else if (symbol.equals("-")) {
            return new SubInterpreter(left, right);
        } else if (symbol.equals("*")) {
            return new MultiInterpreter(left, right);
        } else if (symbol.equals("/")) {
            return new DivInterpreter(left, right);
        }
        return null;
    }
}

